package com.aizhixin.lab.common.entity;

import com.aizhixin.lab.common.core.DataValidity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;

@MappedSuperclass
@ToString
public class AbstractStringEntity implements java.io.Serializable {
    @Id
    @Column(name = "id")
    @Getter
    @Setter
    protected String id;

    @CreatedBy
    @Column(name = "created_by")
    @Getter
    @Setter
    protected Long createdBy;

    @CreatedDate
    @Column(name = "created_date")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Temporal(TemporalType.TIMESTAMP)
    @Getter
    @Setter
    protected Date createdDate=new Date();

    @LastModifiedBy
    @Column(name = "last_modified_by")
    @Getter
    @Setter
    protected Long lastModifiedBy;

    @LastModifiedDate
    @Column(name = "last_modified_date")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Temporal(TemporalType.TIMESTAMP)
    @Getter
    @Setter
    protected Date lastModifiedDate = new Date();

    @Column(name = "delete_flag")
    @Getter
    @Setter
    protected Integer deleteFlag = DataValidity.VALID.getState();
}
